package com.mju.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class GetTheCurrentTimeUtils {
    //获取当前时间（字符串）
    public static String getTheStrCurrentTime(){
        Date currentTime = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return dateFormat.format(currentTime);
    }

    //获取当前时间
    public static Date getTheCurrentTime() throws ParseException {
        return new Date();

    }

    //计算day天后的时间
    public static Date getTheEndTime(String str_time,int day) throws ParseException {
        //格式化
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date time = dateFormat.parse(str_time);
        //格林威治时间
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(time);
//        System.out.println("传入的时间"+dateFormat.format(calendar.getTime()));

        calendar.add(Calendar.DATE,day);
        String endTime=dateFormat.format(calendar.getTime());
        return dateFormat.parse(endTime);
    }

    //比较两个时间大小,true-未过期 false-过期
    public static Boolean compareTime(String time1,String time2){
        int result = time1.compareTo(time2);
        return result >= 0;
    }
}

